Skip to content

🚀 feat(model): add UniNet #2797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

ashwinvaidya17
Copy link
Contributor

@ashwinvaidya17 ashwinvaidya17 commented Jun 26, 2025

📝 Description

Results

Combined

category Original Acc Original AUROC Anomalib AUROC Original F1 Anomalib F1
bottle 100 100 99.76 100 98.39
cable 98.8 97.6 98.18 94.5 93.99
capsule 100 100 94.81 100 95.89
carpet 99.6 98.6 89.61 97.8 89.77
grid 99.2 97.8 100 95 99.12
hazelnut 100 100 99.93 99.3 98.57
leather 100 100 99.39 99.5 97.33
metal_nut 100 100 100 100 99.46
pill 99.7 98.4 96.73 99.3 97.12
screw 100 100 94.14 100 91.83
tile 98.9 96.9 98.48 94.7 95.81
toothbrush 100 100 95.28 100 90.91
transistor 99.2 99.2 98.54 97.5 96.1
wood 99.9 100 99.12 98.4 96.67
zipper 99.7 99 94.01 97.9 95.83

Original

object image_auroc acc f1
carpet 98.6 99.6 97.8
bottle 100 100 100
hazelnut 100 100 99.3
leather 100 100 99.5
cable 97.6 98.8 94.5
capsule 100 100 100
grid 97.8 99.2 95
pill 98.4 99.7 99.3
transistor 99.2 99.2 97.5
metal_nut 100 100 100
screw 100 100 100
toothbrush 100 100 100
zipper 99 99.7 97.9
tile 96.9 98.9 94.7
wood 100 99.9 98.4

Anomalib

data.init_args.category image_AUROC image_F1Score
0 bottle 99.76 98.39
1 cable 98.18 93.99
2 capsule 94.81 95.89
3 carpet 89.61 89.77
4 grid 100 99.12
5 hazelnut 99.93 98.57
6 leather 99.39 97.33
7 metal_nut 100 99.46
8 pill 96.73 97.12
9 screw 94.14 91.83
10 tile 98.48 95.81
11 toothbrush 95.28 90.91
12 transistor 98.54 96.1
13 wood 99.12 96.67
14 zipper 94.01 95.83

Anomaly Map Examples

image
image

✨ Changes

Select what type of change your PR is:

  • 🚀 New feature (non-breaking change which adds functionality)
  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ♻️ Refactor (non-breaking change which refactors the code base)
  • ⚡️ Performance improvements
  • 🎨 Style changes (code style/formatting)
  • 🧪 Tests (adding/modifying tests)
  • 📚 Documentation update
  • 📦 Build system changes
  • 🏗️ CI/CD configuration
  • 🔧 Chore (general maintenance)
  • 🔒 Security update
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).
  • 🏷️ My PR title follows conventional commit format.

For more information about code review checklists, see the Code Review Checklist.

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
@samet-akcay samet-akcay changed the title ✨ UniNet 🚀 feat(model): add UniNet model Jun 26, 2025
@samet-akcay samet-akcay changed the title 🚀 feat(model): add UniNet model 🚀 feat(model): add UniNet Jun 26, 2025
Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
@ashwinvaidya17 ashwinvaidya17 marked this pull request as ready for review July 2, 2025 16:33
ashwinvaidya17 and others added 4 commits July 9, 2025 16:08
Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
Copy link
Contributor

@samet-akcay samet-akcay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the implementation! Only few minor comments

Signed-off-by: Ashwin Vaidya <ashwin.vaidya@intel.com>
Signed-off-by: Ashwin Vaidya <ashwin.vaidya@intel.com>
Signed-off-by: Ashwin Vaidya <ashwin.vaidya@intel.com>
Signed-off-by: Ashwin Vaidya <ashwin.vaidya@intel.com>
@ashwinvaidya17 ashwinvaidya17 requested a review from Copilot July 17, 2025 09:01
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds the UniNet model implementation for anomaly detection to the anomalib library. UniNet is designed for diverse domains and supports both supervised and unsupervised anomaly detection with a focus on multi-class scenarios.

  • Implements complete UniNet model architecture with teachers, student, and bottleneck modules
  • Adds domain-related feature selection and attention bottleneck components
  • Refactors ResNet decoder to be shared between Reverse Distillation and UniNet models

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/anomalib/models/image/uninet/ Complete UniNet model implementation with PyTorch and Lightning modules
src/anomalib/models/components/backbone/ Refactored ResNet decoder to be shared across models
src/anomalib/models/image/reverse_distillation/ Updated imports to use shared decoder component
examples/configs/model/uninet.yaml Configuration file for UniNet model
third-party-programs.txt Added license attribution for UniNet

Signed-off-by: Ashwin Vaidya <ashwin.vaidya@intel.com>
Signed-off-by: Ashwin Vaidya <ashwin.vaidya@intel.com>
@samet-akcay samet-akcay added this to the v2.1.0 milestone Jul 21, 2025
Signed-off-by: Ashwin Vaidya <ashwin.vaidya@intel.com>
Copy link
Contributor

@rajeshgangireddy rajeshgangireddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. I have a few small comments

Decoder network implementation
"""

# Copyright (C) 2025 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright goes to the top?
Same for other files as well.

class AttentionBottleneck(nn.Module):
"""Attention Bottleneck for UniNet."""

expansion: int = 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rename expansion to be a bit more specific or add a comment.

loss: nn.Module,
) -> None:
super().__init__()
self.teachers = Teachers(teacher_backbone)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any advantage of creating the student and bottleneck in lightning model and the teachers in torch model ?

self.bce_loss = torch.nn.BCEWithLogitsLoss()
# Used to post-process the student features from the de_resnet model to get the predictions
self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
self.fc = nn.Linear(256, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this 256 in nn.Linear(256, 1) be valid for the set of possible backbones?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📋 [TASK] Implement UniNet - CVPR 2025
3 participants